﻿<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%option explicit%>
<%
Dim RZ_IN
RZ_IN=1
%>
<!--#include file="../conn.inc.asp" -->
<!--#include file="admin_inc/admin.function.asp" -->
<!--#include file="admin_inc/admin.sqlfunction.asp" -->
<%
'作者：山林客（ah_bill）
'博客：http://ruizhinet.blog.163.com
'网站：http://www.ruizhinet.cn
'本信息不会影响您网站的正常访问，请保留
checkadmin(4)
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模板管理</title>
<link type="text/css" href="style/style.css" rel="stylesheet" rev="stylesheet"/>
<script type="text/javascript" src="admin_js/common.js"></script> 
</head>
<body>
<%
dim rootuploadpath,subdir,filename,currentdir
dim appPath
appPath=replace(LCase(Request.ServerVariables("PATH_INFO")), "admin/manage_template.asp","" )
rootuploadpath = appPath&"template"
subdir=Trim(request("subdir"))
filename=trim(request.QueryString("filename"))
If filename<>"" And instr(filename,".")=0  Then
filename=filename&".html"
End If 
if subdir<>"" then
currentdir=subdir
else
currentdir=rootuploadpath
end if
currentdir=Replace(currentdir,"//","/")

%>
<form name="rzform" action="manage_template.asp" method="post">
<div class="addrecord">模板：
<select name="subdir" id="subdir" onchange="changefolder(this);">
<option value="">请选择模板子目录</option>
<%
dim fso,objFolder,objSubFolders,objSubFolder,subpath
set fso=server.CreateObject("scripting.filesystemobject")
on error resume next
set objFolder=fso.GetFolder(Server.Mappath(rootuploadpath))
set objSubFolders=objFolder.Subfolders
for each objSubFolder in objSubFolders 
subpath=rootuploadpath&"/" + objSubFolder.name
Response.Write("<option value='"&subpath&"'")
if InStr(subdir,subpath)>0 then response.Write(" selected='selected'")
response.Write(">├"&objSubFolder.name&"</option>")
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
%>
</select>
&nbsp;&nbsp;&nbsp;<a href="manage_template_dir.asp">新建模板</a>
</div>
</form>

<table cellspacing="0" cellpadding="0" class="table_800">
<tr><td colspan="5">当前目录：
<%
If subdir="" Then 
response.write("/<a href='?subdir="&currentdir&"'>template</a>")
Else
Dim dir_arr,d_i,d_path,tmp_dir
tmp_dir=Mid(subdir,2)
dir_arr=Split(tmp_dir,"/")
For d_i=0 To UBound(dir_arr)
d_path=d_path&"/"&dir_arr(d_i)
Dim testdir
testdir="/"&dir_arr(d_i)&"/"
testdir=Replace(testdir,"//","/")
If testdir<>RZ_ROOT Then 
response.write("<a href='?subdir="&d_path&"'>/"&dir_arr(d_i)&"</a>")
End If 
Next 
End if
%>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-weight:bold;">新建文件：</span>
<a href="manage_template_edit.asp?subdir=<%=subdir%>&ftype=0&addedit=add">HTML</a>&nbsp;&nbsp;
<a href="manage_template_edit.asp?subdir=<%=subdir%>&ftype=1&addedit=add">CSS</a>&nbsp;&nbsp;
<a href="manage_template_edit.asp?subdir=<%=subdir%>&ftype=2&addedit=add">JavaScript</a>&nbsp;&nbsp;
<a href="manage_template_edit.asp?subdir=<%=subdir%>&ftype=3&addedit=add">XML</a>&nbsp;&nbsp;
<a href="manage_template_edit.asp?subdir=<%=subdir%>&ftype=4&addedit=add">Text</a>
</td></tr>
<tr>
<th>文件名</th><th>类型</th><th>文件大小</th><th>修改时间</th><th>操作</th>
</tr>

<%
On Error Resume Next
dim objFSO
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
If Err.Number=-2147221005 Then 
	Response.Write "您的主机不支持FSO,不能使用该功能"
	Err.Clear
	Response.End
End If
If filename<>"" Then
	If objFSO.Fileexists(Server.Mappath(""&currentdir&"/"&filename)) Then
		objFSO.Deletefile(Server.Mappath(""&currentdir&"/"&filename))
	Else
		Response.Write ""&currentdir&"/"&Request.QueryString("filename")&"不存在"
	End If
End If
dim folder
Set folder=objFSO.Getfolder(Server.Mappath(currentdir))
If Err.Number<>0 Then
    Response.Write ""&Err.Description&""
    Response.End
End If%>
<%
Dim subfolder,subfoldername,subfolderpath,ftype
For   Each   subfolder   in   folder.SubFolders   
subfoldername=SubFolder.Name   
%>
<tr>
<td><img src="images/icon_folder.gif" alt=""><a href="?subdir=<%=currentdir&"/"&subfoldername%>"><%=subfoldername%></a></td>
<td class="tdcenter"><%=SubFolder.Type%></td>
<td class="tdcenter"><%=FormatNumber(folder.size/1024,2)%>K</td>
<td class="tdcenter"><%=SubFolder.DateLastModified%></td>
<td class="tdcenter">
<%If Right(currentdir,9)="/template" And subfoldername<>"default" then%>
<a href="?deltemplate=<%=currentdir&"/"&subfoldername%>"  title="删除"  onclick="return confirm('您确定要删除模板吗？');">删除</a>
<%End if%>
</td>
</tr>
<%
Next 
for Each filename In folder.files
%>
<tr>
<td>
<%If LCase(Right(filename.name,5))=".html" Then
ftype=0
%>
<img src="images/icon_html.gif" alt="HTML">
<%ElseIf LCase(Right(filename.name,4))=".css" Then 
ftype=1
%>
<img src="images/icon_css.gif" alt="CSS">
<%ElseIf LCase(Right(filename.name,3))=".js" Then 
ftype=2
%>
<img src="images/icon_javascript.gif" alt="JavaScript">
<%ElseIf LCase(Right(filename.name,4))=".xml" Then 
ftype=3
%>
<img src="images/icon_xml.gif" alt="Xml">
<%ElseIf LCase(Right(filename.name,4))=".txt" Then 
ftype=4
%>
<img src="images/icon_text.gif" alt="Text">
<%ElseIf LCase(Right(filename.name,4))=".swf" Or LCase(Right(filename.name,4))=".flv" Then 
ftype=""
%>
<img src="images/icon_flash.gif" alt="">
<%ElseIf LCase(Right(filename.name,4))=".gif" Or LCase(Right(filename.name,4))=".jpg" Or LCase(Right(filename.name,4))=".png" Or LCase(Right(filename.name,5))=".jpeg" Then
ftype=""
%>
<img src="images/icon_image.gif" alt="">
<%Else
ftype=""
%>
<img src="images/icon_file.gif" alt="">
<%End If %>
<%=filename.name%>
</td>
<td class="tdcenter"><%=filename.Type%></td>
<td class="tdcenter"><%=FormatNumber(filename.size/1024,2)%>K</td>
<td class="tdcenter"><%=filename.DateLastModified%></td>
<td class="tdcenter">
<%Dim filename_name
If LCase(Right(filename.name,5))=".html" Then 
filename_name=Left(filename.name,Len(filename.name)-5)
Else 
filename_name=filename.name
End If 
%>
<%If ftype<>"" Then %>
<a href="manage_template_edit.asp?addedit=edit&ftype=<%=ftype%>&subdir=<%=subdir%>&file=<%=filename_name%>">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%End If %>
<a href="?subdir=<%=subdir%>&filename=<%=filename_name%>"  title="删除"  onclick="return confirm('您确定要删除吗？');">删除</a>
</td>
</tr>
<%
  	Next
%>
<%
    Set folder=Nothing
	Set objFSO=Nothing
    
%>
</table>
<div class="tdcenter">
<span style="cursor:pointer;" onclick="templatefileupload('image','<%=currentdir%>');">上传图片</span>&nbsp;&nbsp;<span  style="cursor:pointer;" onclick="templatefileupload('flash','<%=currentdir%>');">上传Flash</span>
<div>
<iframe id="templatefileupload" marginwidth="0" marginheight="0" frameborder="0" style="width:400px;height:30px" src="" scrolling="no"></iframe>	
</div>
</div>

</body>
</html>
<%
Dim deltemplate
deltemplate=Trim(request.querystring("deltemplate"))
If deltemplate<>"" Then
	Call DeleteFolder(Server.Mappath(deltemplate))
	response.redirect("manage_template.asp")
End If 
function DeleteFolder(dabspath)
	dim dfso, dfolder, dsubfolders, dfiles, dfile ,dff
	On Error Resume next
	set dfso = server.CreateObject("scripting.filesystemobject")
	set dfolder=dfso.GetFolder(dabspath)
	set dfiles = dfolder.files
	for each dfile in dfiles
		response.write(dfile.path)
		dfso.deletefile dfile.path,true
	next
	set dsubfolders = dfolder.subfolders
	for each dff in dsubfolders
		DeleteFolder(dff.path)
	Next
	dfso.DeleteFolder(dabspath) 
	Set dsubfolders=Nothing
	Set dfiles=Nothing
	Set dfolder=Nothing
	Set dfso=Nothing 
end function

%>